{layout name="common/layout" /}
<!--标签选择-->
<link rel="stylesheet" type="text/css" href="__MERCHANT_STATIC__/beacheck/css/jquery-labelauty.css" />
<script type="text/javascript" src="__MERCHANT_STATIC__/beacheck/js/jquery-labelauty.js"></script>
<!--文件上传-->
<script src="__WWW_STATIC__/lib/plupload/plupload.full.min.js"></script>
<script src="__MERCHANT_STATIC__/style/js/uploadfile/uploadfile.js" type="text/javascript"></script>
<script src="__WWW_STATIC__/lib/fileinput/js/plugins/sortable.js" type="text/javascript"></script>
<style>
	/*标签选择样式*/
	ul.category-tag { list-style-type: none;}
	li.category-tag { display: inline-block;}
	li.category-tag { margin: 10px 0;}
	ul.save-category-tag { list-style-type: none;}
	li.save-category-tag { display: inline-block;}
	li.save-category-tag { margin: 10px 0;}
	ul.lang-tag { list-style-type: none;}
	li.lang-tag { display: inline-block;}
	li.lang-tag { margin: 10px 0;}
	li.save-tag { display: inline-block;}
	li.save-tag { margin: 10px 0;}
	input.labelauty + label {
		font-size: 12px;
	}
	/*必填标注样式*/
	.update_red{
		margin-right: 8px;
		position: relative;
		top:3px;
	}
	.update_bookPubInfo tr{
		background-color: #FFF;
		height: 15px;
	}
	input::-webkit-outer-spin-button,
	input::-webkit-inner-spin-button {
		-webkit-appearance: none;
	}
	input[type="number"]{
		-moz-appearance: textfield;
	}
	.info_title{
		left:15px;
		position: relative;
	}
	.lab {
		font-size: 14px;
		color: #444;
	}
	.text-lab{
		height: 24px;
	}
	/*归还地址全选样式*/
	.checkAll{
		margin-right:5px;
		position: relative;
		top:10px;
		width: 15px;
		height: 15px;
	}
	/*归还地址条目样式*/
	.revet_item{
		position: relative;
		top:10px;
		width: 15px;
		height: 15px;
	}
	ul li {
		cursor: pointer;
	}
	/* 图片上传相关css */
	.update_goodsCommonR {
		padding: 15px;
		box-sizing: border-box;
	}
	.upload_image {
		border: 1px solid #999;
		box-sizing: border-box;
		height: 150px;
		width: 150px;
		display: block;
		background-image: url("__MERCHANT_STATIC__/style/img/upload.png");
	}
	.img_upload_list:after {
		content: "";
		display: block;
		clear: both;
	}

	.img_upload_single {
		margin-right: 15px;
		margin-bottom: 15px;
		width: 150px;
		position: relative;
		float: left;
	}
	.img_upload_single:hover .upload_delete {
		display: block;
		text-decoration: none;
	}
	.img_upload_single:hover .upload_delete {
		display: block;
		text-decoration: none;
	}

	.upload_delete {
		position: absolute;
		height: 30px;
		width: 30px;
		color: #fff !important;
		background-color: #000;
		border-radius: 50%;
		text-align: center;
		line-height: 30px;
		top: -10px;
		right: -10px;
		font-size: 25px;
		display: none;
	}
	.update_goodsCommonMess {
		padding-left: 230px;
		box-sizing: border-box;
	}
</style>
<div class="dislpayArrow hidden-xs"><a class="pngfix" href="javascript:void(0);" onClick="displaynavbar(this)"></a></div>

<!-- main area -->
<div class="Hui-article-box" style="margin-top: 37px;overflow-y:auto">
	<h2 class="update_title">图书&nbsp;>&nbsp;添加系列图书</h2>
	<form id="frm" action="" class="update_form">
		{:token()}
		<div class="update_goodsTop">
			<div  class="lab text-lab">
                        <span><i class="update_red">*</i>ISBN(13位)</span>
						<input type="text" id="book_isbn13" value="{$book_info['isbn13']}" name="isbn13" class="input-text radius size-M"
						placeholder="请填写图书ISBN码(13位)">
            </div>
			<div class="lab text-lab">
				<span><i class="update_red">*</i>书名</span>
				<input type="hidden" name="type" class="handle_type"/>
				<input type="hidden" name="id" value="{$book_info['id']}"/>
				<input type="text" id="book_name" onpropertychange="checkcount()" oninput="checkcount()" name="title" class="input-text radius size-M"
					   placeholder="请输入书名，不超过100个字" style="width: 450px;" value=""/>
				<span id="span_namecount">0/100</span>
				<!--
				<a class="copy_series" style="margin-left:30px;display:{if !empty($book_info['series'])}inline-block{else/}none{/if};" href="{:url('book/copyBook')}?copyid={$book_info['id']}"><input type="button" class="btn" value="复制系列" /></a>
				-->
			</div>
			<div class="lab text-lab">
				<span><i class="update_red">&nbsp;</i>系列名</span>
				<input type="text" id="book_series" onpropertychange="checkcount()" oninput="checkcount()" name="series" class="input-text radius size-M"
					   placeholder="请填写系列名(不是系列图书不用填写)" value="{$book_info['series']}"/>
				<span id="span_seriescount">0/50</span>
			</div>
			<div class="lab text-lab">
				<span><i class="update_red">*</i>作者</span>
				<input type="text" id="book_author" name="author" class="input-text radius size-M"
					   placeholder="请填写作者姓名" value="{$book_info['author']}"/>
			</div>
			<div class="lab text-lab">
				<span><i class="update_red">*</i>出版社</span>
				<input type="text" id="book_publisher" name="publisher" class="input-text radius size-M"
					   placeholder="请填写出版社信息" value="{$book_info['publisher']}"/>
			</div>
			<div class="lab">
				<span><i class="update_red">*</i>出版日期</span>
				<input type="text" id="book_pubdate" name="pub_date" class="input-text radius size-M Wdate"
					   placeholder="请选择出版日期" onClick="WdatePicker({dateFmt:'yyyy-MM'});" value="{$book_info['pub_date']}"/>
			</div>
			<div class="lab">
				<span><i class="update_red">*</i>语言</span>
				<input type="hidden" name="language" value=""/>
				<div class="lang_tag_table" style="width: 60%;position: relative;display: inline-block;margin-left: 30px;" >
					<ul class="lang-tag" style="position: relative;">
						<li class='lang-tag'><input type='checkbox' onclick='checkstatus()' class='lang-bea' value="1" data-labelauty="中文"/></li>&nbsp;
						<li class='lang-tag'><input type='checkbox' onclick='checkstatus()' class='lang-bea' value="4" data-labelauty="中文注音"/></li>&nbsp;
						<li class='lang-tag'><input type='checkbox' onclick='checkstatus()' class='lang-bea' value="2" data-labelauty="英文"/></li>&nbsp;
						<li class='lang-tag'><input type='checkbox' onclick='checkstatus()' class='lang-bea' value="3" data-labelauty="中英文"/></li>&nbsp;
					</ul>
				</div>
			</div>
			<!-- 图书租赁信息 -->
			<div class="lab cl">
				<div class="lab-l"><i class="update_red">*</i>图书租赁信息</div>
				<!-- 图书定价参数说明 -->
				<div class="update_goodsPrice" style="margin-left: 30px;">
					<div class="lab-top">
						<p class="can update_goodsPriceBook" style="width:100px;cursor:pointer">显示参数说明</p>
						<div class="lab-show">
							<div class="update_goodsPrames" style="display:none">
								<table class="table table-border table-bg  table-bordered">
									<tr class="first-tr">
										<th>库存</th>
										<th>售价</th>
										<th>折扣</th>
										<th>折扣价</th>
										<th>书架号</th>
									</tr>
									<tr>
										<td>单本图书在商家仓库中的总数</td>
										<td>图书的定价</td>
										<td>图书打折百分比</td>
										<td>图书打折后价格</td>
										<td>图书在商家仓库的编号，填写后方便商家发货或者归还时，快速找到图书的位置</td>
									</tr>
								</table>
							</div>
						</div>
					</div>

					<div class="te goods_price_check">
						<!-- 图书定价信息 -->
						<div class="update_goodsColorSize">
							<table class="table table-border table-bg  table-bordered" style="width: 100%;">
								<tr class="text-c text-cs">
									<td width="120px;"><i class="update_red">*</i>库存</td>
									<td><i class="update_red">*</i>售价</td>
									<td>折扣</td>
									<td>折扣价</td>
									<td>书架号</td>
								</tr>
								<tr class="text-c">
									<td width="120px;">
										<input name="stock" id="book_stock" min="0" onkeyup="clearNoNumAndPoint(this)" value="{$book_info['stock']}" type="number" class="input-text radius size-M" style="width: 70px;" > 本
									</td>
									<td>
										<input name="price" min="0" onkeyup="clearNoNum(this)" id="book_price" type="number" value="{$book_info['price']}" class="input-text radius size-M" style="width: 70px;"> 元
									</td>
									<td>
										<input name="discount" min="0" onkeyup="clearNoNum(this)" max="100" id="book_discount" type="number" value="{$book_info['discount']}" class="input-text radius size-M" style="width: 70px;"> %
									</td>
									<td>
										<input min="0" id="book_discount_price" type="number" class="input-text radius size-M" style="width: 70px;background-color: #fff;" disabled> 元
									</td>
									<td>
										<input name="shelf_mark" id="book_shelf_mark" type="text" value="{$book_info['shelf_mark']}" class="input-text radius size-M" style="width: 180px;margin-right: 10px;">
									</td>
								</tr>
							</table>
						</div>
					</div>
				</div>
			</div>
			<!-- 图书租赁信息 -->
			<div class="lab">
				<span><i class="update_red">*</i>适读年龄</span>
				<input type="number" min="0" id="book_min_age" name="min_age" class="input-text radius" value="{$book_info['min_age']}"/>
				<span style="margin-left: 25px;">--</span>
				<input type="number" min="1" style="margin-right: 5px;" id="book_max_age" name="max_age" class="input-text radius" value="{if condition="$book_info['max_age'] gt '0'"}{$book_info['max_age']}{else/}{/if}"/>
				<span id="span_subnamecount" style="margin-left: 5px;">岁</span>
			</div>
			<div class="lab">
				<span><i class="update_red">*</i>图书分类标签</span>
				<input type="hidden" name="category-tag" />
				<span id="span_catname" style="margin-right:10px"></span>
				<div class="save_tag_table" style="width: 60%;position: relative;display: inline-block;margin-left: 20px;" >
					<a class="show_tag" href="javascript:showtag();" style="margin-left:20px;display: none;">点击添加图书标签</a>
					<!--分类标签处理-->
					<div class="save-book-category-tag">
						<ul class="save-category-tag">
							{foreach $category as $kca => $vca}
							<li class='save-category-tag'><input type='checkbox' class='save-bea' value="{$vca['id']}" data-labelauty="{$vca['name']}"/></li>&nbsp;
							{/foreach}
						</ul>
					</div>
				</div>
				<div class="tag_table" style="width: 60%;position: relative;display: none;" >
					<!--分类标签处理-->
					<div class="book-category-tag">
						<ul class="category-tag">
							{foreach $category as $kca => $vca}
							<li class='category-tag'><input type='checkbox' onclick='checkstatus()' class='bea' value="{$vca['id']}" data-labelauty="{$vca['name']}"/></li>&nbsp;
							{/foreach}
						</ul>
					</div>
					<!--<a class="sel_all" style="margin-left:10px;"><input type="button" class="btn" value="全选" /></a>
                    <a class="re_sel" style="margin-left:10px;"><input type="button" class="btn" value="反选" /></a>
                    <a class="save_tag" style="margin-left:10px;"><input type="button" class="btn" value="确认" /></a>
                    <a class="cancel_save_tag" style="margin-left:10px;"><input type="button" class="btn" value="取消" /></a>-->
				</div>
			</div>
			<div class="lab">
				<span><i class="update_red">*</i>摘要</span>
				<textarea id="book_summary" name="summary" style="right: -15px;margin-left: 20px;margin-top:8px;position: relative;width:360px;height: 160px;resize: vertical;" placeholder="请输入图书摘要信息">{$book_info['summary']}</textarea>
			</div>
		</div>
		<div class="update_goodsBottom">
			<div id="vue-contaniner">
				<!-- 图书封面(小) -->
				<div class="lab cl">
					<div class="lab-l"><i class="update_red">*</i>图书封面(小)</div>
					<p class="update_goodsCommonMess">展示在列表上的图书封面小图（图书图片比例为1：1，建议尺寸：480x480像素，支持png、jpg、gif等基本图片格式，图片小于2M）</p>
					<div class="lab-r update_goodsCommonR" style="position: relative;padding-bottom:0">
						<ul class="goods_mainimg_list img_upload_list">
							<li class="goods_mainimg_add img_upload_single">
								<img class="upload_image">
							</li>
							<button type="button" style="display:none" id="hidden_imgmain"></button>
							<!-- 数据隐藏域； -->
							<input id="id_file_cover" type="hidden" name="file_cover[]" />
						</ul>
					</div>
				</div>
				<!-- 图书封面(小) -->
				<!-- 图书详情 -->
				<div class="lab cl">
					<div class="lab-l" style="position: relative;">
						<i class="update_red">&nbsp;</i>图书详情
					</div>
					<p class="update_goodsCommonMess">图片建议宽为 620像素，高度无限制，图片仅支持JPG、GIF、PNG格式，图片要小于2M</p>

					<div class="lab-r update_goodsCommonR" style="padding-bottom:0">
						<ul class="goods_more_list img_upload_list" id="goods_more_list" style="position:relative">
							<li class="goods_more_add img_upload_single">
								<img class="upload_image">
							</li>
						</ul>
						<button type="button" style="display:none" id="hidden_more"></button>
						<!-- 数据隐藏域； -->
						<input type="hidden" value="" id="ipt_book_details_images" name="book_details_images">
					</div>
				</div>
				<!-- 图书详情 -->
				<!-- 图书基本信息 -->
				<div class="lab cl">
					<div class="lab-l">图书信息</div>
					<a class="show_book_info" href="javascript:showbookinfo();" style="top:7px;position: relative;">点击添加图书信息（完善图书信息，更方便用户找到您的商品）</a>
					<div class="update_goodsTypeChoose" style="border: 0px;display: none;">
						<div class="update_bookPubInfo">
							<table class="table-bg table-border" style="width:60%;border: 0px;">
								<tr class="text-c text-cs">
									<td class="info_title">ISBN(10位)</td>
									<td>
										<input type="text" id="book_isbn10" name="isbn10" value="{$book_info['isbn10']}" class="input-text radius size-M"
											   style="right: 30px;position: relative;background-color: #fff;border:0px;" placeholder="请填写图书ISBN码(10位)">
									</td>
								</tr>

								<tr class="text-c text-cs">
									<td class="info_title">副书名</td>
									<td>
										<input type="text" id="book_subtitle" value="{$book_info['subtitle']}" name="subtitle" class="input-text radius size-M"
											   style="right: 30px;position: relative;" placeholder="请填写图书副书名">
									</td>
								</tr>
								<tr class="text-c text-cs">
									<td class="info_title">原书名</td>
									<td>
										<input type="text" id="book_origin_title" value="{$book_info['origin_title']}" name="origin_title" class="input-text radius size-M"
											   style="right: 30px;position: relative;" placeholder="请填写原书名">
									</td>
								</tr>
								<!--
								<tr class="text-c text-cs">
									<td class="info_title">系列</td>
									<td>
										<input type="text" id="book_series" value="{$book_info['series']}" name="series" class="input-text radius size-M"
											   style="right: 30px;position: relative;" placeholder="请填写系列名(不是系列不用填写)">
									</td>
								</tr>
								-->
								<tr class="text-c text-cs">
									<td class="info_title">翻译员</td>
									<td>
										<input type="text" id="book_translator" value="{$book_info['translator']}" name="translator" class="input-text radius size-M"
											   style="right: 30px;position: relative;" placeholder="请填写翻译员姓名">
									</td>
								</tr>
								<tr class="text-c text-cs">
									<td class="info_title">图书评分(豆瓣)</td>
									<td>
										<input type="number" min="0" disabled id="book_level_num" value="{$book_info['level_num']}" name="level_num" class="input-text radius size-M"
											   style="right: 55px;position: relative;width: 250px;background-color: #fff;border:0px;" placeholder="请填写图书评分">
									</td>
								</tr>
								<tr class="text-c text-cs">
									<td class="info_title">装帧方式</td>
									<td>
										<input type="text" id="book_binding" value="{$book_info['binding']}" name="binding" class="input-text radius size-M"
											   style="right: 30px;position: relative;" placeholder="请填写装帧方式(现代装帧方式：精装、平装)">
									</td>
								</tr>
								<tr class="text-c text-cs">
									<td class="info_title">页数</td>
									<td>
										<input type="number" min="0" id="book_pages" value="{$book_info['pages']}" name="pages" class="input-text radius size-M"
											   style="right: 50px;position: relative;width:250px;" placeholder="请输入页数">页
									</td>
								</tr>
								<tr class="text-c text-cs">
									<td class="info_title"><i class="update_red">*</i>最少提前天数</td>
									<td>
										<input type="number" min="0" id="book_least_advance_days" value="{$book_info['least_advance_days']}" name="least_advance_days" class="input-text radius size-M"
											   style="right: 50px;position: relative;width:250px;" placeholder="请输入最少提前天数">天
									</td>
								</tr>
								<tr class="text-c text-cs">
									<td class="info_title"><i class="update_red">*</i>最多提前月数</td>
									<td>
										<input type="number" min="0" id="book_max_advance_days" value="{$book_info['max_advance_days']}" name="max_advance_days" class="input-text radius size-M"
											   style="right: 50px;position: relative;width:250px;" placeholder="请输入最多提前月数">月
									</td>
								</tr>
							</table>
						</div>
						<!-- 归还地址 -->
						<div class="lab cl">
							<div class="lab-l" style="width: 370px;"><i class="update_red">*</i>归还地址
								<a style="line-height:35px;margin-left:25px" href="javascript:void(0);" onclick="getretun_address()">刷新</a>
								<a target="view_window" href="{:url('revert/add')}">添加归还地址</a>
							</div>
							<!-- 刷新 -->
							<div class="lab-r update_goodsCommonR" style="border:0;margin-top: 10px;">
								<div style="max-height:250px;overflow-y:auto;margin-top:10px;">
									<table class="table table-border table-bg  table-bordered update_addresschange">
										<tr class="text-c first-tr">
											<td>姓名</td>
											<td>收货地址</td>
											<td><input class="checkAll" type="checkbox" checked>全选</td>
										</tr>
										{foreach $return_place as $k5 => $v5}
										<tr class="text-c">
											<td>{$v5['revent_receiver_name']}</td>
											<td>{$v5['revent_province']}{$v5['revent_city']}{$v5['revent_region']}{$v5['revent_detailed_address']}</td>
											<td>
												<input type="checkbox" class="input revet_item" id="ipt_revert" name="revert_id[]" value="{$v5['revert_id']}" checked/>
											</td>
										</tr>
										{/foreach}
									</table>
								</div>
							</div>
						</div>
						<!-- 归还地址 -->
					</div>
				</div>
				<!-- 图书基本信息 -->
				<div class="mac">
					{if condition="$book_info['status'] eq '2'"}
					<input type="button" value="上架" class="btn" onclick="savebook(2);">
					{else/}
					<input type="button" value="上架" class="btn" onclick="savebook(2);">
					<input type="button" value="保存" class="btn" onclick="savebook(1);">
					{/if}
					<input type="button" value="返回" class="btn"  onclick="window.history.go(-1);">
				</div>
			</div>
	</form>
</div>
<script type="text/javascript">
    var htmltypedata=null;
    var uploadurl="{:url('book/uploadImg')}";
    /*标签处理*/
    var tag_arr = new Array();
    function checkstatus(){
        var usertag = "";
        $("input.bea:checked").each(function(){
            usertag += this.value+",";
        });
        //$("#usertag").val(usertag);
    }
    $(':input.bea').labelauty();
    $(':input.save-bea').labelauty();
    $(':input.lang-bea').labelauty();
    $(':input.lang-bea').each(function () {
        if($(this).val() == "{$book_info['language']}"){
            $(this).prop("checked","checked");
        }
    });
    {foreach $book_category as $kca => $vca}
    $(':input.save-bea').each(function () {
        if($(this).val() == "{$vca['id']}"){
            $(this).prop("checked","checked");
        }
    });
    {/foreach}
    //$(".language").val("{$book_info['language']}");
    $("#span_namecount").html($("#book_name").val().length + '/100');
    $("#span_seriescount").html($("#book_series").val().length + '/50');
    $("#book_discount_price").val(($("#book_price").val()*$("#book_discount").val()/100).toFixed(2));
    $("#book_discount").keyup(function () {
        var price = $("#book_price").val();
        var discount = $(this).val();
        var discount_price = price*discount/100;
        $("#book_discount_price").val(discount_price.toFixed(2));
    });
	$("#book_price").keyup(function () {
		var price = $(this).val();
		var discount = $("#book_discount").val();
		var discount_price = price*discount/100;
		$("#book_discount_price").val(discount_price.toFixed(2));
	});
    function showtag(){
        tag_arr.splice(0,tag_arr.length);
        $(".tag_table").show();
        $(".tag_table").css("display","inline-block");
        //$(".show_tag").hide();
        $(".save_tag_table").hide();
    }
    //全选
    $(".sel_all").click(function () {
        $(".category-tag").each(function () {
            $(this).find(":input.bea").prop("checked","checked");
        });
    });
    //语言按钮单选控制
    $(".lang-bea").click(function () {
        var tag_value = 0;
        $(":input.lang-bea:checked").each(function () {
            tag_value += 1;
        });
        if(tag_value > 1){
            layer.msg("只能选择一种语言");
            $(this).removeAttr("checked");
            return false;
        }
    });
	//分类按钮个数(5个)控制
	$(".save-bea").click(function () {
		var tag_value = 0;
		$(":input.save-bea:checked").each(function () {
			tag_value += 1;
		});
		if(tag_value > 5){
			layer.msg("最多只能选择五个分类");
			$(this).removeAttr("checked");
			return false;
		}
	});
    //确认
    $(".save_tag").click(function () {
        tag_arr.splice(0,tag_arr.length);
        var id = 0;
        var name = '';
        $("input.bea:checked").each(function () {
            id = $(this).val();
            name = $(this).closest("li.category-tag").find("span.labelauty-checked").text();
            tag_arr.push({id:id,name:name});
        });
        $(".save-category-tag").html("");
        for(var i=0;i<tag_arr.length;i++){
            $(".save-category-tag").append("<li class='save-tag'><input type='checkbox' checked disabled class='save-bea' value='"+tag_arr[i].id+"' data-labelauty='"+tag_arr[i].name+"'/></li>&nbsp;");
        }
        $(".tag_table").hide();
        $(".save_tag_table").show();
        $(".save_tag_table").css("display","inline-block");
        $(':input.save-bea').labelauty();
        tag_arr.splice(0,tag_arr.length);
    });
    //取消
    $(".cancel_save_tag").click(function () {
        tag_arr.splice(0,tag_arr.length);
        $(".tag_table").hide();
        $(".save_tag_table").show();
    });
    /*标签处理*/
    /*展示编辑图书信息*/
    function showbookinfo(){
        $(".update_goodsTypeChoose").show();
        $(".show_book_info").hide();
    }
    /**
     * 刷新归还地址数据
     */
    function getretun_address(){
        $.ajax({
            type: "get",
            url: "{:url('revert/getRevert')}",
            dataType: 'json',
            cache: false,
            success: function (data) {
                data=data.data;
                //console.log(data);
                var firsttr='<tr class="text-c first-tr"><td>姓名</td><td>收货地址</td><td><input class="checkAll" type="checkbox" style="margin-right:5px;">全选</td></tr>';
                var lasttr="";
                for (var i = 0; i < data.length; i++) {
                    lasttr+='<tr class="text-c"><td>'+data[i].revert_name+'</td><td>'+data[i].revent_address+'</td><td><input type="checkbox" class="input revet_item" id="ipt_revert" name="goods_revert_id[]" value='+data[i].revert_id+'></td></tr>';
                }
                firsttr+=lasttr;
                $(".update_addresschange").html("");
                $(".update_addresschange").append(firsttr);
            },
            error: function (xhr, status, error) {
            }
        });
    }
    $('.update_addresschange').on('click','.checkAll',function () {
        //$("#ipt_revert").val("");
        if ($('.checkAll').prop('checked')) {
            $('.input').prop('checked', true);
        } else {
            $('.input').prop('checked', false);
        }
    });
    var $input = $('.input').not('.checkAll');
    $input.on('change', function () {
        if ($('.input:checked').not('.checkAll').length == $input.size()) {
            $('.checkAll').prop('checked', true);
        } else {
            $('.checkAll').prop('checked', false);
        }
    });
</script>
<script type="text/javascript" src="__MERCHANT_STATIC__/style/js/uploadImg.js?v=1.0"></script>
<script type="text/javascript">
    goods_mainimg_number = parseInt("{$book_info['medium_num']}");
    goods_more_number = parseInt("{$book_info['main_num']}");
    $(function () {
        $.Huitab("#tab_demo .tabBar span", "#tab_demo .tabCon", "current", "click", "0")
    });

    /**
     * 数据规范化函数只能是数字
     */
    function clearNoNumAndPoint(obj){
        obj.value = obj.value.replace(/[^\d]/g,"");  //清除“数字”和“.”以外的字符
        obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        if(obj.value.indexOf(".")< 0 && obj.value !=""){
            //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
            obj.value= parseFloat(obj.value);
        }
    }

    /**
     * 数据规范化函数只能是最多两位小数的数字
     */
    function clearNoNum(obj){
        obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符
        obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的
        obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数
        if(obj.value.indexOf(".")< 0 && obj.value !=""){
            //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
            obj.value= parseFloat(obj.value);
        }
    }

    /******************表单验证操作******************/
    function checktosave() {
        //验证书名
        if ($("#book_name").val() == '') {
            layer.msg("图书名称不能为空!");
            $("#book_name").focus();
            return false;
        }
        //验证作者
        if ($("#book_author").val() == '') {
            layer.msg("图书作者不能为空!");
            $("#book_author").focus();
            return false;
        }
        //验证出版社
        if ($("#book_publisher").val() == '') {
            layer.msg("图书出版社不能为空!");
            $("#book_publisher").focus();
            return false;
        }
        //验证出版日期
        if ($("#book_pubdate").val() == '') {
            layer.msg("图书出版日期不能为空!");
            $("#book_pubdate").focus();
            return false;
        }
        //语言标签
        var lang_value = "";
        $(":input.lang-bea:checked").each(function () {
            lang_value += $(this).val();
        });
        if(lang_value == ""){
            layer.msg("图书语言至少选择一种");
            $(".Hui-article-box").scrollTop(0)
            return false;
        }
        //验证出版日期
        if ($("#book_price").val() == '' && parseInt($("#book_price").val()) <= 0) {
            layer.msg("图书售价不能为空,且必须为大于0!");
            $("#book_price").focus();
            return false;
        }
        //适读年龄
        if ($("#book_min_age").val() == '') {
            layer.msg("适读年龄不能为空!");
            $("#book_min_age").focus();
            return false;
        }
        //适读年龄
        if ($("#book_max_age").val() == '') {
            layer.msg("适读年龄不能为空!");
            $("#book_max_age").focus();
            return false;
        }
        //适读年龄
        if (parseInt($("#book_max_age").val()) <= 0 || parseInt($("#book_max_age").val()) < parseInt($("#book_min_age").val())) {
            layer.msg("适读年龄填写有误!最大年龄不能小于0,最大年龄不能小于最小年龄");
            $(".Hui-article-box").scrollTop(0)
            return false;
        }
        //图书分类标签
        var tag_value = "";
        $(":input.save-bea:checked").each(function () {
            tag_value += $(this).val();
        });
        if(tag_value == ""){
            layer.msg("图书分类标签不能为空，请至少选择一个");
            $(".Hui-article-box").scrollTop(0)
            return false;
        }
        //验证摘要
        if ($("#book_summary").val() == '') {
            layer.msg("图书摘要不能为空!");
            $("#book_summary").focus();
            return false;
        }
        //验证库存
        if ($("#book_stock").val() == '' || parseInt($("#book_stock").val()) < 0) {
            layer.msg("库存不能为空,请填写最小为0的数值!");
            $("#book_stock").focus();
            return false;
        }
        //验证最小提前
        if ($("#book_least_advance_days").val() == '' || parseInt($("#book_least_advance_days").val()) < 0) {
            layer.msg("最少提前不能为空,请填写最小为0的数值!");
            $("#book_least_advance_days").focus();
            return false;
        }
        //验证最多提前
        if ($("#book_max_advance_days").val() == '' || parseInt($("#book_max_advance_days").val()) < 0) {
            layer.msg("最多提前不能为空,请填写最小为0的数值!");
            $("#book_max_advance_days").focus();
            return false;
        }
        //判断归还地址
        var goods_revert_id_bool = false;
        $("input[name='revert_id[]']").each(
            function () {
                if ($(this).prop("checked")) {
                    goods_revert_id_bool = true;
                    return false;
                }
            }
        );
        if (!goods_revert_id_bool) {
            layer.msg("归还地址不能为空!");
            return false;
        }
        return true;
    }

    /**
     * 添加图书保存数据
     */
    function savebook(type) {
        //表单验证，信息最终提交
        if (!checktosave()) {
            return false;
        }
        if (!goods_mainimg_formUpload()) {
            layer.alert("图书封面(小)不能为空");
            return false;
        }
        if (!goods_more_formUpload()) {
        	layer.alert("图书详情不能为空");
        	return false;
        }
        $(".handle_type").val(type);
        var tag_value = "";
        $(":input.save-bea:checked").each(function () {
            tag_value += $(this).val()+",";
        });
        tag_value = tag_value.substr(0,tag_value.length-1);
        $(":input[name='category-tag']").val(tag_value);
        var lang = $(":input.lang-bea:checked").val();
        $(":input[name='language']").val(lang);
        $.ajax({
            type: "POST",
            url: "<?php echo url('book/addBookInfo', '', false); ?>",
            dataType: 'json',
            cache: false,
            data: $('#frm').serialize(),
            success: function (data) {
                if (data.status == 1) {
                    layer.msg('保存成功!', {
                        //发布成功!
                        time: 1000, //2s后自动关闭
                    });
                    location.href = "{:url('book/listbook')}?page="+"{$page}"+"&type="+"{$type}"+"&keyword="+"{$keyword}"+"&begintime="+"{$begintime}"+"&endtime="+"{$endtime}";
                } else {
                    layer.msg(data.msg);
                }

            },
            error: function (xhr, status, error) {
                console.log(xhr);
                console.log(status);
                console.log(error);
            }
        });

    }
    $(function () {
        $.Huitab("#tab_demo .tabBar span", "#tab_demo .tabCon", "current", "click", "0")
    });

    // 参数说明点击切换和显示
    $('.can').on('click', function () {
        if ($('.update_goodsPrames').is(":hidden")) {
            $('.update_goodsPrames').fadeIn();
            $('.can').text("隐藏参数说明");
        } else {
            $('.update_goodsPrames').fadeOut();
            $('.can').text("显示参数说明");
        }
    })

    function tpClick(obj) {
        $(obj).parent('.td-hide').hide();
        $(obj).parent('.td-hide').siblings('.td-show').show();
    }

    function inputShow(obj) {
        $(obj).siblings().show();
    }

    function liShow(obj) {
        var tw = $(obj).val();
        if (tw == '') {
            $(obj).siblings().show();
            $(obj).hide();
        } else {
            $(obj).hide();
            $(obj).parent('.tab-list').siblings().find('.tr-te').first().children().val(tw);
        }
    }
    var m = 13;
    var n = 133;

    function dellist(obj) {
        $(obj).parent().remove();
        add();
        $('.box2').hide();
    }

    var arr = [];
    var dx = arr.length + 1;

    //判断书名和副书名长度
    function checkcount() {
        if ($("#book_name").val().length > 100) {
            layer.msg("书名长度不能超过100!");
            $("#book_name").val($("#book_name").val().substr(0, 100));
            return;
        }
        $("#span_namecount").html($("#book_name").val().length + '/100');
        if ($("#book_series").val().length > 50) {
            layer.msg("系列名长度不能超过50!");
            $("#book_series").val($("#book_series").val().substr(0, 50));
            return;
        }
        $("#span_seriescount").html($("#book_series").val().length + '/50');
    }
</script>
</body>

</html>